package org.lex.game.sudoku.model;

import java.util.HashSet;
import java.util.Set;

public class CheckResult {
	private boolean valid;
	private Set<Point> duplicates = null;

	public CheckResult() {
		this(true);
	}

	public CheckResult(boolean valid) {
		this.valid = valid;
		this.duplicates = new HashSet<Point>(4);
	}

	public CheckResult(Set<Point> duplicates) {
		this.valid = duplicates.isEmpty();
		this.duplicates = duplicates;
	}

	public boolean isValid() {
		return valid;
	}

	public CheckResult setValid(boolean valid) {
		this.valid = valid;
		return this;
	}

	public Set<Point> getDuplicates() {
		return duplicates;
	}

	public void addDuplicate(int row, int column) {
		this.addDuplicate(new Point(row, column));
	}

	public void addDuplicate(Point p) {
		this.getDuplicates().add(p);
	}

	public CheckResult merge(CheckResult other) {
		this.valid = this.valid && other.valid;
		this.duplicates.addAll(other.duplicates);
		return this;
	}

	@Override
	public String toString() {
		return "ValidateResult [valid=" + valid + ", duplicates=" + duplicates + "]";
	}
}
